package com.xbts.screen.service.impl;

import com.xbts.common.core.enums.WorkshopTypeEnum;
import com.xbts.common.core.utils.DateUtils;
import com.xbts.common.core.web.domain.BaseHistogramResult;
import com.xbts.common.core.web.domain.BasePieChartResult;
import com.xbts.screen.domain.workshop.dto.CommonQueryDTO;
import com.xbts.screen.domain.workshop.vo.*;
import com.xbts.screen.mapper.PlatingMapper;
import com.xbts.screen.service.IPlatingService;
import com.xbts.screen.service.IWorkshopCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 电镀
 */
@Service
public class PlatingServerImpl implements IPlatingService {

    @Autowired
    private PlatingMapper platingMapper;

    @Autowired
    private IWorkshopCommonService workshopCommonService;


    @Override
    public RealTimeAchievementRateVO realTimeAchievementRate() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.realTimeAchievementRate(dto);
    }

    @Override
    public BaseHistogramResult tenDaysAchievementRate() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.tenDaysAchievementRate(dto);
    }

    @Override
    public StatisticalRateGroupByTimeVO achievementRateGroupByTimeType() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.achievementRateGroupByTimeType(dto);
    }

    @Override
    public BaseHistogramResult waterUnitConsume() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.waterUnitConsume(dto);
    }

    @Override
    public BaseHistogramResult electricityUnitConsume() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.electricityUnitConsume(dto);
    }

    @Override
    public List<ProductionScheduleVO> productionSchedule() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.productionSchedule(dto);
    }

    @Override
    public BaseHistogramResult turnoverRate() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.turnoverRate(dto);
    }

    @Override
    public StatisticalRateGroupByTimeVO turnoverRateGroupByTimeType() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.turnoverRateGroupByTimeType(dto);
    }

    @Override
    public PassRateVO passRate() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        List<String> todayDate = DateUtils.getTodayDate();
        dto.setStartTime(todayDate.get(0));
        dto.setEndTime(todayDate.get(1));
        PassRateVO todayVo = workshopCommonService.passRate(dto);
        if (todayVo == null) {
            todayVo = new PassRateVO();
            todayVo.setDefectNum("0");
        }
        List<String> currentMonth = DateUtils.getCurrentMonth();
        dto.setStartTime(currentMonth.get(0));
        dto.setEndTime(currentMonth.get(1));
        PassRateVO monthVo = workshopCommonService.passRate(dto);
        if (monthVo == null) {
            monthVo = new PassRateVO();
            monthVo.setInspectNum("0");
            monthVo.setPassNum("0");
            monthVo.setDefectNum("0");
            monthVo.setDefectRate("0");
        }
        monthVo.setDefectNum(todayVo.getDefectNum());
        return monthVo;
    }

    @Override
    public List<BasePieChartResult> badStatistics() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.badStatistics(dto);
    }

    @Override
    public List<PassRateRecordVO> passRateRecord() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.passRateRecord(dto);
    }

    @Override
    public RealTimeAchievementRateVO firstPassRate() {
        return null;
    }

    @Override
    public RealTimeAchievementRateVO secondaryPassRate() {
        return null;
    }

    @Override
    public ScrapRateVO scrapRate() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.scrapRate(dto);
    }

    @Override
    public List<BasePieChartResult> scrapStatistics() {
        CommonQueryDTO dto = new CommonQueryDTO();
        dto.setDeptNames(Arrays.asList(WorkshopTypeEnum.PLATING.getErpValue().split(",")));
        return workshopCommonService.scrapStatistics(dto);
    }
}